﻿using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Gauges
{
    public class ColorPointCollection : ObservableCollection<ColorPoint>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorPointCollection"/> class.
        /// </summary>
        public ColorPointCollection()
        {
        }

        /// <summary>
        /// Get the Range with which to render an item at the specified 
        /// point in the range. If the value is below the value of the first color point we
        /// return the first color point, if it is greater than the last, we return that
        /// </summary>
        /// <param name="position">The value in the range at which you want to get 
        /// color to render an item</param>
        /// <returns>The color point for the psition</returns>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Color", Justification = "We support U.S. naming in a British project")]
        public ColorPoint GetColor(double position)
        {
            ColorPoint res = null;
            foreach (ColorPoint point in this)
            {
                if (position >= point.Value)
                {
                    res = point;
                }
            }

            if (res == null && this.Count > 0)
            {
                return this[0];
            }

            return res;
        }
    }
}
